if (typeof (model) == 'undefined')
	model = {};
if (typeof (model.course) == 'undefined')
	model.course = {};

if (typeof (model.course.factory) == 'undefined')
	model.course.factory = {};

function Course(options) {
	var settings = $.extend({
		course : {}
	}, options || {});

	var self = this;
	self.id = ko.observable(settings.course.id);
	self.timeTables = ko.observableArray();
	self.name = ko.observable(settings.course.name);
	self.enable = ko.observable(settings.course.enable);
	self.description = ko.observable(settings.course.description);
	self.tag = ko.observable(settings.course.tag);
	self.getAllTimeTable = function(){
		var url = 'course/json/get-timetable.action?cid=' + self.id();
		var results;
		
		$.getJSON(url, function(json){
			results = json;
		});
		model.course.pushJsonInTimeTableArray(results.tts, self.timeTables());
		return results;
	};
	return this;
};

model.course.pushJsonInTimeTableArray = function(orig, dest){
	$.each(orig, function(index, item){
		var timeTable = new TimeTable(item);
		dest.push(timeTable);
	});
};

model.course.factory.create = function(options){
	return new Course(options);
};